package com.tensquare.user.controller;

import com.tensquare.entity.Result;
import com.tensquare.user.pojo.User;
import com.tensquare.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author BAO
 * @version V1.0
 * @Package com.tensquare.user.controller
 * @date 2020/12/5 18:17
 * @description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody User user){
        User login = userService.login(user);
        return login!=null?Result.success("login success",user):Result.fail("login fail");
    }


    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String userId){
        User user = userService.findById(userId);
        return user!=null?Result.success("success",user):Result.fail("fail");
    }
}
